package com.jucai.pppeiyouclient.view.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.jucai.pppeiyouclient.MainActivity;
import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.BaseActivity;
import com.jucai.pppeiyouclient.comm.CommonRequestNetData;
import com.jucai.pppeiyouclient.utils.ActivityCollector;
import com.jucai.pppeiyouclient.utils.LogUtils;
import com.jucai.pppeiyouclient.utils.ToastUtils;

import java.util.HashMap;

public class AppendContentActivity extends BaseActivity {
    private static final String TAG = "AppendContentActivity : ";
    private TextView additionTitle, additionSubmit;
    private EditText additionalContent;

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_append_content);
        ((TextView) findViewById(R.id.common_title_text)).setText("追加内容");
        additionTitle = (TextView) findViewById(R.id.addition_title);
        additionSubmit = (TextView) findViewById(R.id.addition_submit);
        additionalContent = (EditText) findViewById(R.id.additional_content);
    }

    @Override
    protected void initData() {
        additionTitle.setText(getIntent().getStringExtra("act_title"));
    }

    @Override
    protected void loadNetData() {

    }

    @Override
    protected void setListener() {
        findViewById(R.id.common_back).setOnClickListener(this);
        findViewById(R.id.common_home_back).setOnClickListener(this);
        additionSubmit.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_back:
                ActivityCollector.removeActivity(this);
                break;

            case R.id.common_home_back:
                startActivity(new Intent(AppendContentActivity.this, MainActivity.class));
                ActivityCollector.removeActivity(this);
                break;

            case R.id.addition_submit:
                if (TextUtils.isEmpty(additionalContent.getText().toString())) {
                    ToastUtils.showToast("添加内容不可为空哦~");
                } else {
                    HashMap<String, String> param = new HashMap<>();
                    param.put("id", getIntent().getStringExtra("act_id"));
                    param.put("service", "Conductor_Activity.additional");
                    param.put("additional", additionalContent.getText().toString());
                    LogUtils.e(TAG + "param = " + param);

                    CommonRequestNetData.getJsonStringData(AppendContentActivity.this, param, true,new CommonRequestNetData.JsonStringCallBack() {
                        @Override
                        public void parseJsonString(String str) {
                            LogUtils.e(TAG + "str = " + str);
                            ToastUtils.showToast("追加内容成功");
                            ActivityCollector.removeActivity(AppendContentActivity.this);
                        }
                    });
                }
                break;

            default:
                break;
        }
    }

    public static void startAppend(Context context, String activityTitle, String activityId) {
        Intent intent = new Intent(context, AppendContentActivity.class);
        intent.putExtra("act_title", activityTitle);
        intent.putExtra("act_id", activityId);
        context.startActivity(intent);
    }
}
